package com.jingyanku.service.impl;

import com.base.service.impl.ServiceImpl;
import com.jingyanku.pojo.Thread;
import com.jingyanku.service.IThreadService;
public class ThreadServiceImpl<T extends Thread> extends ServiceImpl<T>implements IThreadService<T> {

	@Override
	@SuppressWarnings("all")
	public boolean create(T thread) {

		dao.create(thread);

		int totalCount = dao.getTotalCount(" select count(t) from Thread t "
				+ " where t.deleted = false and t.board.id = "
				+ thread.getBoard().getId(), null);

		dao
				.createQuery(
						" update Board b "
								+ " set b.lastThread.id ="+thread.getId()+", b.lastReply.id = null, threadCount = "+totalCount +" where b.id ="+thread.getBoard().getId()).executeUpdate();
     return true;
	}

	public void updateHit(Integer threadId) {

		dao.createQuery(
				" update Thread t set t.hit = t.hit + 1 where t.id =  "+threadId).executeUpdate();

	}

}
